// 允许出现重复数字
export function generateRandomArray(n: number, minValue: number, maxValue: number): number[] {
    if (minValue > maxValue) {
        throw new Error("minValue must be less than or equal to maxValue");
    }

    let array: number[] = [];
    for (let i = 0; i < n; i++) {
        array.push(Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue);
    }
    return array;
}

function shuffleArray(arr: number[]): number[] {
    for (let i = arr.length - 1; i > 0; i--) {
        let j = Math.floor(Math.random() * (i + 1));
        [arr[i], arr[j]] = [arr[j], arr[i]];
    }
    return arr;
}

// 不允许出现重复数字
export function generateUniqueRandomArray(n: number, minValue: number, maxValue: number): number[] {
    if (n > maxValue - minValue + 1) {
        throw new Error("n cannot be greater than the range of values");
    }

    let array: number[] = [];
    for (let i = minValue; i <= maxValue; i++) {
        array.push(i);
    }
    shuffleArray(array);
    return array.slice(0, n);
}
